package com.afei.java.ai.langchain4j;

import dev.langchain4j.community.model.dashscope.WanxImageModel;
import dev.langchain4j.data.image.Image;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.Response;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.net.URI;

/**
 * @Title: langchan4j
 * @Author wangyf
 * @Package com.afei.java.ai
 * @Date 2025/4/22 14:42
 * @description: 测试langchan4j
 */

@SpringBootTest
public class langchan4j {


    @Test
    public void testGPTDemo() {

        //初始化模型
        OpenAiChatModel model = OpenAiChatModel.builder()
//LangChain4j提供的代理服务器，该代理服务器会将演示密钥替换成真实密钥， 再将请求转发给OpenAI API
                .baseUrl("http://langchain4j.dev/demo/openai/v1") //设置模型api地址（如果apiKey="demo"，则可省略baseUrl的配置）
                .apiKey("demo") //设置模型apiKey
                .modelName("gpt-4o-mini") //设置模型名称
                .build();
        //向模型提问
        String answer = model.chat("你是谁呀？");
        System.out.println(answer);

    }


    @Autowired
    private ChatLanguageModel chatLanguageModel;

    @Test
    public void testSpringBoot() {
        String answer = chatLanguageModel.chat("我是谁?");
        System.out.println(answer);
    }

    @Test
    public void testDashScopeWanx() {
        WanxImageModel wanxImageModel = WanxImageModel
                .builder()
                .modelName("wanx2.1-t2i-turbo").
                apiKey("sk-1cf641b7ca204081acac994a0646dd25")
                .build();

        Response<Image> response = wanxImageModel.generate("帮我生成一个智能客服平台的log图");
        URI url = response.content().url();
        System.out.println(url);


    }
}
